package com.guavamail.smtp;

import java.util.ArrayList;
import java.util.Collection;

public class SessionStatus {

	private boolean authenticating = false;
	private boolean authenticated = false;
	private boolean dataMode = false;
	private boolean hasSeenHelo = false;
	private boolean active = true;
	private boolean hasSender = false;

	/** 发件人 */
	private String from = null;

	/** 收件人 */
	private Collection<String> recipients = null;

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
		setHasSender(true);
	}

	public void addRecipient(String recipient) {
		if (recipients == null)
			recipients = new ArrayList<String>();

		recipients.add(recipient);
	}

	public Collection<String> getRecipients() {
		return recipients;
	}

	public void setRecipients(Collection<String> recipients) {
		this.recipients = recipients;
	}

	public boolean isActive() {
		return this.active;
	}

	public void quit() {
		this.active = false;
	}

	public boolean getHasSender() {
		return this.hasSender;
	}

	public void setHasSender(boolean value) {
		this.hasSender = value;
	}

	public boolean getHasSeenHelo() {
		return this.hasSeenHelo;
	}

	public void setHasSeenHelo(boolean hasSeenHelo) {
		this.hasSeenHelo = hasSeenHelo;
	}

	public boolean isDataMode() {
		return this.dataMode;
	}

	public void setDataMode(boolean dataMode) {
		this.dataMode = dataMode;
	}

	public int getRecipientCount() {
		if (recipients == null)
			return 0;

		return recipients.size();
	}

	public boolean isAuthenticated() {
		return authenticated;
	}

	public void setAuthenticated(boolean authenticated) {
		this.authenticated = authenticated;
	}

	public boolean isAuthenticating() {
		return authenticating;
	}

	public void setAuthenticating(boolean authenticating) {
		this.authenticating = authenticating;
	}

	/**
	 * Executes a full reset() of the session which requires a new HELO command
	 * to be sent
	 */
	public void resetAll() {
		reset(false);
		setAuthenticated(false);
	}

	/**
	 * Reset session, but don't require new HELO/EHLO
	 */
	public void reset() {
		reset(true);
	}

	private void reset(boolean hasSeenHelo) {
		this.hasSender = false;
		this.dataMode = false;
		this.active = true;
		this.hasSeenHelo = hasSeenHelo;
	}
}
